package com.lixunhuan.handacount.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lixunhuan.handacount.common.ResultInfo;
import com.lixunhuan.handacount.db.bean.HandAcount;
import com.lixunhuan.handacount.db.mapper.HandAcountMapper;
import com.lixunhuan.handacount.service.IHandAcountService;
import com.lixunhuan.handacount.vo.HandDetailsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author lixunhuan
 * @since 2021-03-19
 */
@Service
public class HandAcountServiceImpl extends ServiceImpl<HandAcountMapper, HandAcount> implements IHandAcountService {

    private static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    @Autowired
    private HandAcountMapper handAcountMapper;

    @Override
    public ResultInfo getAcountdetail(String uid, Integer type) {
        List<HandDetailsVo> handDetailsVos = new ArrayList<>();
        handAcountMapper.dateList(type, uid).forEach(o -> {
            HandDetailsVo handDetailsVo = new HandDetailsVo();
            if (format.format(new Date()).equals(o)) {
                handDetailsVo.setDate("今天");
            } else if (format.format(System.currentTimeMillis() - 1000 * 60 * 60 * 24).equals(o)) {
                handDetailsVo.setDate("昨天");
            } else {
                handDetailsVo.setDate(o);
            }
            handDetailsVo.setTotal(handAcountMapper.total(o, type, uid));
            handDetailsVo.setHandAcountVoList(handAcountMapper.getHandAcountListsByDetail(o, type, uid));
            handDetailsVos.add(handDetailsVo);
        });
        return new ResultInfo(ResultInfo.Status.SUCCESS).result(handDetailsVos);
    }
}
